<template>
  <div class="cont-top-box">
    <el-form label-width="100px">
      <el-form-item label="部门">
        <el-checkbox-group v-model="departmentChecks" style="display:inline-block">
          <el-checkbox v-for="item in departmentList" :key="item.id" :label="item.id" @change="checkChange">{{ item.name }}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="社保城市">
        <el-checkbox-group v-model="socialSecurityChecks" style="display:inline-block">
          <el-checkbox v-for="item in cityList" :key="item.id" :label="item.id" @change="checkChange">{{ item.name }}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>

      <el-form-item label="公积金城市">
        <el-checkbox-group v-model="providentFundChecks" style="display:inline-block">
          <el-checkbox v-for="item in cityList" :key="item.id" :label="item.id" @change="checkChange">{{ item.name }}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getDepartments } from '@/api/departments'
import { getCityList } from '@/api/common'
export default {
  data() {
    return {
      tip: {},
      departmentChecks: [], // 筛选部门
      socialSecurityChecks: [], // 社保城市
      providentFundChecks: [], // 公积金城市
      departmentList: [], // 部门
      cityList: [] // 城市列表
    }
  },
  created() {
    this.getDepartments()
    this.getCityList()
  },
  methods: {
    // 点击筛选
    checkChange() {
      const selectParams = {
        'departmentChecks': this.departmentChecks,
        'socialSecurityChecks': this.socialSecurityChecks,
        'providentFundChecks': this.providentFundChecks
      }
      // 子传父
      this.$parent.changSelectParams && this.$parent.changSelectParams(selectParams)
    },
    // 获取部门
    async getDepartments() {
      const { depts } = await getDepartments()
      this.departmentList = depts
    },
    // 获取城市
    async getCityList() {
      this.cityList = await getCityList()
    }
  }
}
</script>

<style>

</style>
